<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

if ( ! function_exists('f_input'))
{
    function f_input($name, $value = '', $type = '')
    {
       echo form_label(ucfirst($name).': ', $name);
	   echo form_error($name, '<div class="form-error">', '</div>');
	   $form_attr = array('name' => $name, 'id' => $name); 
	   
	   if($value != '')
	   {
			$form_attr['value'] = $value;
	   }
	   else
	   {
			$form_attr['value'] = set_value($name);
	   }
	   
	   if(form_error($name)){
			$form_attr['class'] = 'input-error';
	   }
	   
	   if($type == '')
	   {
		   echo form_input($form_attr);
	   }
	   else
	   {
			if($type == 'password')
				echo form_password($form_attr);
	   }
	   	
	   
    }   
}

if ( ! function_exists('pre'))
{
	function pre($data)
	{
		print_r($data);	
	}
}

if ( ! function_exists('clean_post'))
{
	function clean_post($value, $post)
	{
		$data = array();
		$data = $post;
		unset($data[$value]);
		return $data;
	}
}

if ( ! function_exists('flash'))
{
	function flash()
	{
		
		$CI =& get_instance();
		if($CI->session->flashdata('type')){
			echo '<div class="msg '.$CI->session->flashdata('type').'"><span></span><h5>'.ucfirst($CI->session->flashdata('type')).'</h5>'.$CI->session->flashdata('msg').'</div>';
		}
	}
}

if ( ! function_exists('set_redirect'))
{
	function set_redirect($type, $msg, $redirect = '')
	{
		
		$CI =& get_instance();
		$flashdata = array('type' => $type, 'msg' => $msg);
		$CI->session->set_flashdata($flashdata);
		if($redirect != '') redirect($redirect);
		
	}
}

if ( ! function_exists('generatePassword'))
{
	function generatePassword($length=9) {
		$vowels = 'AEUY123456789#@!';
		$consonants = 'BDGHJMNPQRSTVZ';
		
	 
		$password = '';
		$alt = time() % 2;
		for ($i = 0; $i < $length; $i++) {
			if ($alt == 1) {
				$password .= $consonants[(rand() % strlen($consonants))];
				$alt = 0;
			} else {
				$password .= $vowels[(rand() % strlen($vowels))];
				$alt = 1;
			}
		}
		return $password;
	}
}

if ( ! function_exists('is_customer_logged_in'))
{
	function is_customer_logged_in(){
		$CI =& get_instance();
		return $CI->session->userdata('customer_logged_in');
	}
	
}
 
?>